#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/types.h>
int main(){
  int pipefd[2] = {0};
  if(pipe(pipefd) != 0){//创建管道
    perror("pipe error!\n");
    return 1;
  }
  
  if(fork() == 0){
    close(pipefd[1]);//关闭写端
    char buffer[1024] = {0};
    ssize_t s = read(pipefd[0], buffer, sizeof(buffer)-1);
    if(s > 0){
      buffer[s] = 0;
      printf("dad say----> %s\n", buffer);
    }
    exit(1);
  }

  close(pipefd[0]);//关闭读端
  const char* msg = "i am father";
  write(pipefd[1], msg, strlen(msg));
  
  return 0;
}
